package br.mywallet.view;

import java.util.List;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListView;
import br.mywallet.data.ContaDAO;
import com.mywallet.R;

public class ContaListagem extends Activity {

	private ListView listView;
	private ListViewAdapter adapter;
	private List<? extends ItemListView> itens;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_conta_listagem);

		listView = (ListView) findViewById(R.id.listView);

		itens = (new ContaDAO()).listarConta(this);

		if (itens != null) {
			adapter = new ListViewAdapter(this, itens);

			listView.setAdapter(adapter);
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.conta_listagem, menu);

		return true;
	}

	@Override
	public boolean onMenuItemSelected(int id, MenuItem item) {
		Intent it;
		switch (item.getItemId()) {
		case R.id.menu_conta_inserir:
			it = new Intent(this, ContaIncluir.class);
			startActivity(it);
			return false;
		}
		return false;
	}

}
